package com.map;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Set;

public class PropertiesTest1 {
	public static void main(String[] args) {
		Properties p = new Properties();// Map<String string>
		// 设置属性
		p.setProperty("admin", "张三");
		p.setProperty("acount", "value");
		System.out.println(p);
		
		//从文件中装载配置文件
		InputStream in;
		 try {	 
			in = new FileInputStream(new File("d:\\upload\\a.txt"));
			p.load(in);
		} catch (FileNotFoundException e) {
			
			e.printStackTrace();
			System.out.println("配置文件未找到");
		}catch (IOException e) {
			e.printStackTrace();
			System.out.println("读取配置文件未失败");
		}
		System.out.println();
		
		
		 try {
				in = new FileInputStream(new File("d:\\upload\\a.txt"));
				p.load(in);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				System.out.println("配置文件未找到");
			}catch (IOException e) {
				e.printStackTrace();
				System.out.println("读取配置文件未失败");
			}
			System.out.println();
			
			
			
			try {
				FileInputStream it = new FileInputStream(new File("d:\\upload\\a.txt"));
				 Reader reader = new InputStreamReader(it, "GBK");
				p.load(reader);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				System.out.println("配置文件未找到");
			}catch (IOException e) {
				e.printStackTrace();
				System.out.println("读取配置文件未失败");
			}
			System.out.println(p);
			
			
			//配置文件的保存
	}
}
